package leetcode.editor.cn.q1_300.q50;

/**
 * @author qidi
 * @date 2021-12-21 15:03:44
 */
class Q0083_RemoveDuplicatesFromSortedList {

    private static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public ListNode deleteDuplicates(ListNode head) {
            if (head == null || head.next == null) return head;

            ListNode nHead = head;
            ListNode tail = head;
            while (head != null) {
                if (tail.val != head.val) {
                    tail.next = head;
                    tail = tail.next;
                }
                head = head.next;
            }

            tail.next = null;

            return nHead;
        }
    }
    //leetcode submit region end(Prohibit modification and deletion)


    public static void main(String[] args) {
        Solution solution = new Q0083_RemoveDuplicatesFromSortedList().new Solution();
        ListNode node = new ListNode(1);
        ListNode node1 = new ListNode(1);
        ListNode node2 = new ListNode(3);
        ListNode node3 = new ListNode(3);
        ListNode node4 = new ListNode(4);
        ListNode node5 = new ListNode(4);
        ListNode node6 = new ListNode(5);

        node.next = node1;
//        node1.next = node2;
//        node2.next = node3;
//        node3.next = node4;
//        node4.next = node5;
//        node5.next = node6;

        solution.deleteDuplicates(node);
    }
}